package com.njmaomao.gj.pyot.common.exception;

import com.njmaomao.gj.pyot.common.bean.Response;

/**
 * 依赖系统业务失败
 *
 * @author hh
 *         2017年4月26日
 */
public class ExternalSystemBizFail extends RuntimeException/* extends RemoteCallBizException*/ {

    private static final long serialVersionUID = 450681067074732794L;

    private Object response;

    public ExternalSystemBizFail(Object response) {
        this.response = response;
    }

    public Object getResponse() {
        return response;
    }

    public static void whenIf(boolean condition, Response response, String url) {
        if(condition) {
            String[] urlArray = url.split("/");
            String system = urlArray.length < 4 ? url : urlArray[3];
            response.setDesc(String.join(": ", system, response.getDesc()));
            throw new ExternalSystemBizFail(response);
        }
    }

}
